package com.xhj.springbootproject.controller;

import com.xhj.springbootproject.service.intf.SendMailService;
import com.xhj.springbootproject.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：Xionghaijun
 * @date ：Created in 2019/7/24 4:49 PM
 * @description： 邮件测试类
 */
@RestController
public class SendMailController {

    @Value("${spring.mail.send.to}")
    private String sendTo;

    @Autowired
    private SendMailService sendMailService;

    @RequestMapping(value = "/sendMail", method = RequestMethod.GET)
    public JsonResult sendMail() {

        //发送简单邮件
        sendMailService.sendSimpleMail(sendTo,"简单邮件测试","你好，这是简单邮件测试");
        //发送html邮件
        String content = "<html>\n" +
                "<body>\n"
                +"<h2>html邮件内容</h2><br><marquee>你好，这是html邮件测试</marquee>\n"
                +"</body></html>";
        sendMailService.sendHtmlMail(sendTo,"html邮件测试",content);
        //发送附件邮件示例
        String content1 = "<html>\n" +
                "<body>\n"
                +"<h2>html邮件内容</h2><br><marquee>你好，这是html邮件测试</marquee>\n"
                +"</body></html>";
        sendMailService.sendAttachmentsMail(sendTo,"附件邮件测试",content1,"/Users/xionghaijun/Documents/图片/杭州地铁路线.png");

        //发送图片邮件示例
        String resId ="pic001";
        String content2 = "<html>\n" +
                "<body><h2>html邮件内容</h2><br><img src=\'cid:"+resId+"\'></img></body>" +
                "</html>";
        //发图片邮件
        sendMailService.sendInlinResourceMail(sendTo,"图片邮件测试",
                content2,"/Users/xionghaijun/Documents/图片/杭州地铁路线.png",resId);

        return JsonResult.getSuccessResult().fillData("邮件发送成功");
    }

    public static void main(String[] args) {
        System.out.println();
    }
}
